import random
a = [random.randint(0,50) for i in range(10)]
print("原始数组：",a)

def partition(arr,left,right):
    '''
    完成第一次快排后，返回第一个值所在位置的索引
    '''
    i = left
    j = right
    pivot = arr[left]
    while i < j:
        while i < j and arr[j] > pivot:
            j -= 1
        while i < j and arr[i] <= pivot:
            i += 1
        if i < j:
            arr[i],arr[j] = arr[j],arr[i]
    arr[left],arr[i] = arr[i],arr[left]
    return i

def quicksort(arr,left,right):
    if left < right:
        pivot_index = partition(arr,left,right)
        quicksort(arr,left,pivot_index - 1)
        quicksort(arr,pivot_index + 1,right)

#执行快速排序
quicksort(a,0,len(a) - 1)
print("排序后的数组：",a)
print("最小值：%d" % a[0])
print("最大值：%d" % a[len(a) - 1])

    
